<?php

namespace addons\payment\controller;

use app\admin\model\payment\Order;
use think\addons\Controller;

class Index extends Controller
{

    public function index()
    {
        $this->error("当前插件暂无前台页面");
    }

    public function payweb() {
        $order_number = $this->request->param('order_number');
        $order = Order::get(['order_number' => $order_number]);
        if (!$order) {
            $this->error('未找到订单');
        }
        $channel = $order->channel;
        if (!$channel) {
            $this->error('支付渠道不存在!');
        }
        $service = $channel->getService();
        if ($service === false) {
            $this->error($channel->getError());
        }
        $res = $service->payWeb($order);
        return $res;
    }

    public function qrcode() {
        $order_number = $this->request->param('order_number');
        $order = Order::get(['order_number' => $order_number]);
        if (!$order) {
            $this->error('未找到订单');
        }
        $channel = $order->channel;
        if (!$channel) {
            $this->error('支付渠道不存在!');
        }
        $service = $channel->getService();
        if ($service === false) {
            return $this->error($channel->getError());
        }
        $res = $service->payScan($order);
        $this->assign('qrcode', $res);
        return $this->view->fetch();
    }

}
